//Hyper-Point class supporting KDTree class

package edu.wlu.cs.levy.kdTree;

import java.util.Arrays;

public class HPoint {

	protected double [] coord;

	protected HPoint(int n) {
		coord = new double [n];
	}

	public HPoint(double [] x) {

		coord = new double[x.length];
		System.arraycopy(x, 0, coord, 0, x.length);
	}

	protected Object clone() {

		return new HPoint(coord);
	}

	protected boolean equals(HPoint p) {

//		return java.util.Arrays.equals(p.coord, coord);
		// seems faster than java.util.Arrays.equals(), which is not 
		// currently supported by Matlab anyway
		for (int i=0; i<coord.length; ++i)
			if (coord[i] != p.coord[i])
				return false;

		return true;
	}
	public double sqrdist(HPoint y){
		return sqrdist(this, y);
	}

	protected static double sqrdist(HPoint x, HPoint y) {

		double dist = 0;

		for (int i=0; i<x.coord.length; ++i) {
			double diff = (x.coord[i] - y.coord[i]);
			dist += (diff*diff);
		}

		return dist;

	}

	protected static double eucdist(HPoint x, HPoint y) {

		return Math.sqrt(sqrdist(x, y));
	}
	public String csvString(){
		String s = "";
		for (int i = 0; i<coord.length-1; i++){
			s+=""+coord[i]+",";
		}
		s+=""+coord[coord.length-1];
		return s;
	}

	public String toString() {
		return Arrays.toString(coord);
	}
}
